package com.volunteer.controller;

import com.volunteer.common.Result;
import com.volunteer.entity.Evaluation;
import com.volunteer.service.EvaluationService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评价控制器
 */
@RestController
@RequestMapping("/api/evaluations")
@RequiredArgsConstructor
public class EvaluationController {

    private final EvaluationService evaluationService;

    /**
     * 获取活动的评价列表
     */
    @GetMapping("/activity/{activityId}")
    public Result<List<Evaluation>> getActivityEvaluations(@PathVariable Long activityId) {
        List<Evaluation> evaluations = evaluationService.getActivityEvaluations(activityId);
        return Result.success(evaluations);
    }

    /**
     * 创建评价
     */
    @PostMapping
    public Result<Evaluation> createEvaluation(@RequestBody Evaluation evaluation) {
        Evaluation created = evaluationService.createEvaluation(evaluation);
        return Result.success("评价成功", created);
    }

    /**
     * 删除评价（管理员）
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<Void> deleteEvaluation(@PathVariable Long id) {
        evaluationService.deleteEvaluation(id);
        return Result.success("删除成功", null);
    }
}

